package com.matt.domain.observation;

import com.matt.commons.model.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.Date;
import java.util.Map;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/8/11
 * *******************************
 */
@Data
@Table(name = "observation_new_option")
@Entity
@EqualsAndHashCode(callSuper = true)
public class ObservationNewOption extends Model{

    @Column(columnDefinition = "varchar(1024) COMMENT '题目'")
    private String title;

    @Column(columnDefinition = "int default 0 COMMENT '分值'")
    private Integer score;

    @Column(columnDefinition = "varchar(32) COMMENT '对应观测点id'")
    private String observationId;

    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '是否删除 0：否，1是' ")
    private Boolean deleted = false;

    @Column(columnDefinition = "int default 0 COMMENT '顺序值'")
    private Integer orderIndex;

    public static ObservationNewOption of(Map optionMap, String observationId, Integer orderIndex){
        ObservationNewOption option = new ObservationNewOption();
        option.setTitle(optionMap.get("title").toString());
        if(optionMap.get("score").toString()==""){
        	 option.setScore(0);
        }else{
             option.setScore(Integer.valueOf(optionMap.get("score").toString()));
        }
        option.setOrderIndex(orderIndex);
        option.setObservationId(observationId);
        return option;
    }

}
